package com.weshare.test;

import com.weshare.job.FileBackupJob;
import com.weshare.model.FileCustom;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class GenerateTestData {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Test
    public void testGenerateTestData() {

        clearTestFiles();
        generateTestFiles();
    }

    private void generateTestFiles() {
        List<FileCustom> files = new ArrayList<>();
        for (int i = 1; i < 11; i++) {
            files.add(new FileCustom(String.valueOf(i), "文件" + i, "text", "content" + i));
            files.add(new FileCustom(String.valueOf(i + 10), "文件" + (i + 10), "image", "content" + (i + 10)));
            files.add(new FileCustom(String.valueOf(i + 20), "文件" + (i + 20), "radio", "content" + (i + 20)));
            files.add(new FileCustom(String.valueOf(i + 30), "文件" + (i + 30), "vedio", "content" + (i + 30)));
        }
        for (FileCustom file : files) {
            jdbcTemplate.update("insert into t_file (id,name,type ,content,backedUp) values (?,?,?,?,?)",
                    new Object[]{file.getId(), file.getName(), file.getType(), file.getContent(), file.getBackedUp()});
        }

    }

    private void clearTestFiles() {
        jdbcTemplate.update("delete from t_file");
    }
}
